package montreal.demo.it;

import java.io.File;
import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;

import org.apache.cactus.ServletTestCase;
import org.apache.cactus.WebRequest;
import org.apache.cactus.WebResponse;
import org.apache.cactus.extension.jetty.Jetty5xTestSetup;

import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;

public class JettyTestCase extends ServletTestCase {
	private final static String BASE_DIR = System.getProperty("user.dir");

	protected void setUp() throws Exception {
		super.setUp();

	}

	protected void tearDown() throws Exception {
		super.tearDown();
	}

	public static Test suite() {
		TestSuite suite = new TestSuite();
		suite.addTestSuite(JettyTestCase.class);
		System.setProperty("cactus.contextURL", "http://localhost:8080/test");
		Jetty5xTestSetup jettyTestSetup = new Jetty5xTestSetup(suite);
		jettyTestSetup.setResourceDir(new File(BASE_DIR + "/target/cargo"));
		
		return jettyTestSetup;
	}

	public void testJsp() throws ServletException, IOException {
		RequestDispatcher dispatcher = request.getRequestDispatcher("/test.jsp");
		dispatcher.forward(request, response);
	}

	public void endJsp(WebResponse response){
		System.out.println(response.getText());
	}
}
